<?php

header("Content-Type:application/json;charset=utf-8");
header("Access-Control-Allow-Origin:*");
if ($_SERVER["REQUEST_METHOD"]=="POST"){
    if(isset($_REQUEST["uname"])&&isset($_REQUEST["upwd"])){
        $uname=$_REQUEST["uname"];
        $upwd=$_REQUEST["upwd"];
        //1.准备链接数据库的配置信息
        $host="127.0.0.1";
        $name="root";
        $pwd="";
        $port="3306";
        $db="mia";
        //2.创建链接
        $conn=new mysqli($host,$name,$pwd,$db,$port);
        //3.设置链接字符集
        mysqli_query($conn,"SET NAMES UTF8");
        //4.准备sql语句
        $sql="  SELECT `uid`,`uname`,`utel` FROM userinfo WHERE uname='".$uname."' AND upwd='".$upwd."'";
        //5.执行sql语句
        $reuslt = $conn->query($sql);
        $arr = array("msg" => "登录失败", "status" => -1, "data" => "");
        if ($reuslt->num_rows >= 1) {
            $arr["msg"] = "登录成功";
            $arr["status"] = "1";
            $arr["data"] = $reuslt->fetch_assoc();
        }

        print_r(json_encode($arr));


        $conn->close();
    }
}
